#include "TM1629.h"
#include "main.h"

void I2C_Start()
{
	CLK_1_1;
	DIO_1_1;
	Delay_us(20);
	
	DIO_1_0;
	Delay_us(20);
	
	CLK_1_0;
	Delay_us(20);
}

void I2C_Stop()
{
	CLK_1_0;
	Delay_us(20);
	DIO_1_0;
	Delay_us(20);
	
	CLK_1_1;
	Delay_us(20);
	
	DIO_1_1;
	Delay_us(20);
}

void TM1629_1_WriteBit(unsigned char bit)
{
	CLK_1_0;
	Delay_us(20);
	if(bit)
	{
		DIO_1_1;
	}
	else
	{
		DIO_1_0
	}
	Delay_us(20);
	CLK_1_1;
	Delay_us(20);
}

void TM1629_1_WriteByte(unsigned char byte)
{
	char loop = 0;
	for(loop = 0;loop < 8;loop++)
	{
		TM1629_1_WriteBit((byte>>loop) & 0x01);
	}
	CLK_1_0;
	Delay_us(20);
	DIO_1_1;
	Delay_us(20);
	CLK_1_1
}

void TM1629_1_WriteCommand(unsigned char mData)
{
	I2C_Start();
	TM1629_1_WriteByte(mData);
	I2C_Stop();
}	

void TM1629_1_WriteData(unsigned char addr,unsigned char mData)
{
	I2C_Start();
	TM1629_1_WriteByte(addr);
	TM1629_1_WriteByte(mData);
	I2C_Stop();
}

void TM1629_DATA_Display()
{
	TM1629_1_WriteCommand(0x44);
}




